package se.sll.itintegration.catalogue.gui.service.view.capacity;

import java.util.Set;
import se.sll.itintegration.catalogue.gui.entity.CareUnitEntity;
import se.sll.service.catalogue.common.Translator;
import se.sll.service.catalogue.common.data.UnitId;
import se.sll.service.catalogue.common.data.UnitList;

/**
 * Translates from Set<CareUnitEntity> to UnitList.
 * 
 * @author Christer Palm, Nogui
 */
public class UnitListTranslator implements Translator<Set<CareUnitEntity>, UnitList> {
    private static final UnitListTranslator INSTANCE = new UnitListTranslator();

    private UnitListTranslator() {
    }

    @Override
    public UnitList translate(Set<CareUnitEntity> from) {
        return translateTo(from, new UnitList());
    }

    @Override
    public UnitList translateTo(Set<CareUnitEntity> from, UnitList to) {
        for (CareUnitEntity cue : from) {
            UnitId u = new UnitId();
            u.setUnitId(cue.getHsaID());
            to.addUnit(u);
        }
        return to;
    }

    public static UnitListTranslator getInstance() {
        return INSTANCE;
    }
}
